<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<% String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>返利账号列表</title>
    <jsp:include page="../import.jsp" flush="true"/>
</head>
<script type="text/javascript">
	var grid = null;
	var pageInTab=null;
	$(function(){
		 initTab();
		var _url = '<%=path%>/rebacc/salerebaccinfo/initList.do'
		$("#ligergrid1").ligerGrid({
			url: _url,
	    	method : 'get',
			columns: [
		            { display: '审核状态', name:'audStsCdNm',align:'center', width: 100},
		            { display: '状态', name: 'assStsCd',width: 60,width:80,
		            	render: function (rowdata, rowindex, value){
		            		var p = '';
		            		if('valid' == rowdata.accStsCd || 'VALID' == rowdata.accStsCd){
		            			p = '有效';
		            		}else if('INVALID' == rowdata.accStsCd || 'invalid' == rowdata.accStsCd){
		            			p = '无效';
		            		}else if('VOID' == rowdata.accStsCd || 'void' == rowdata.accStsCd){
		            			p = '作废';
		            		}
		            		
		            		return p ;
		            	}
		            },
		            { display: '收款方', name: 'rcptUnt', align:'center', width: 100 },
		            { display: '收款账号', name: 'accNo', align:'center', width: 180},
		            { display: '开户行', width: 80,name: 'bkNm',width: 200},
	                { display: '开户行行号', width: 80,name: 'bkNo'},
					{ display: '账号类型', name: 'bizTypCdNm', align:'center', width: 150},
					{ display: '来源', name: 'fromSourceNm', align:'center', width: 80},
					{ display: '流程编号', name: 'pno', align:'center', width: 150,
						render: function (rowdata, rowindex, value){
							var pno = rowdata.pno;
		                    var audStsCd = rowdata.audStsCd;
		                    var pinstId = rowdata.pinstId;
		                    var dataId = rowdata.id;
		                    if(StringUtils.isNotEmpty(pinstId)
	                        && StringUtils.isNotEmpty(audStsCd)
	                        && StringUtils.isNotEmpty(dataId)
	                        && StringUtils.isNotEmpty(pno)){
	                        var h='<a href="javascript:showFlow(';
	                        h+="'"+pinstId+"'";
	                        h+=",'"+audStsCd+"'";
	                        h+=",'"+dataId+"'";
	                        h+=')">'+pno+'</a>';
	                        return h;	
		                    }
						}
					},
					{ display: '操作', name: '', align:'left',width:300, 
						render: function (rowdata, rowindex, value){
							var str = "";
							var g='<a class="sq-button-hasicon" href="javascript:change(';
		            		g+="'"+rowdata.id+"'";
		                    g+=')"><i class="sqBtnIco_4"></i>修改账号用途</a>';
		                    
		                    var s = '<a class="sq-button-hasicon" href="javascript:modifyAccStsCd(';
		            		s+="'"+rowdata.id+"'";
		            		s+=",'start'"
		                    s+=')"><i class="sqBtnIco_4"></i>启用</a>';
		                    
		                    var c = '<a class="sq-button-hasicon" href="javascript:modifyAccStsCd(';
		            		c+="'"+rowdata.id+"'";
		            		c+=",'cancel'"
		                    c+=')"><i class="sqBtnIco_4"></i>作废</a>';

		                    var f = '<a class="sq-button-hasicon" href="javascript:addFlowStart(';
		            		f+="'"+rowdata.id+"'";
		                    f+=')"><i class="sqBtnIco_3"></i>发起审核流程</a>';

		                    str += g ;
		                    if('valid' == rowdata.accStsCd || 'VALID' == rowdata.accStsCd){
		                    	if(rowdata.audStsCd != 1 && rowdata.audStsCd != 2){
		            				str += c;
		                    	}
		            		}else if('void' == rowdata.accStsCd || 'VOID' == rowdata.accStsCd){
		            			str += s;
		            		}
		                    if(('3' == rowdata.audStsCd ||  '0' == rowdata.audStsCd) && rowdata.accStsCd != 'VOID' && rowdata.accStsCd != 'void'){
		                    	str += f ;
		                    }
		                    return str ;
						},
						}
			        ],
			        pageSize:10,
			        root:'rows',
			        record:'total',
			        hideLoadButton : true,
			        width: '100%',
			        height:'100%',
			        heightDiff:-2,
			        checkbox:true,
			        fixedCellHeight: false,
			        rownumbers:true,
//					onAfterShowData: getFlowIds,
		});
		
		grid = liger.get("ligergrid1");
	    grid.setHeight(100);
	    $("#searchBar").ligerForm();
	    $("#searchBtn").click(function(event) {
	         var form = new liger.get("searchBar");
	         var data = form.getData();
	         console.log(JSON.stringify(data));
	         for (name in data){
	            grid.setParm(name,data[name]);
	         };
	        grid.reload();
	    });
	    $("#clearBtn").click(function(event) {
	        $("#resetBtn").click();  //重置 input-text
	        var form = liger.get("searchBar");
	        form.setData({  //重置select等特殊表单
	            "rcptUnt": " ",
	            "accNo": " ",
	            "bkNm": " ",
	            "audStsCd": " ",
	            "bizTypCd": " ",
	        });
	    });
	});
	 var loadedTabs = [];
	    //初始化Tab页签
	    function initTab(){
	        pageInTab = $("#pageInTab").ligerTab({
	            height: 'auto',
	            contextmenu: false,
	            minIframeHeight: GET_minIframeHeight(),
	            onBeforeSelectTabItem: function(tabid) {
	                var selectedRows = grid.getSelectedRows();
	                if(tabid!="tabA"){
	                    if (selectedRows.length != 1) {
	                        $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
	                        return false;
	                    }
	                }
	            },
	            onAfterSelectTabItem: function(tabid) {

	                var selectedRows = grid.getSelectedRows();
	                if(tabid!="tabA"){
	                    if (selectedRows.length != 1) {
	                        $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
	                        return false;
	                    }else{
	                        if (loadedTabs.indexOf(selectedRows[0].id)<0) {
	                            loadedTabs = [];
	                            loadedTabs.push(selectedRows[0].id);
	                            console.log(tabid);
	                            switch (tabid){
	                                case "tabB":
	                                    console.log(tabid)
	                                    pageInTab.setTabItemSrc(tabid, "<%=path%>/project/prjbscinfo/toMfrPrjBscInfoDetailList.do?accId="+selectedRows[0].id);
	                                    break;
	                            }
	                        }


	                        SetIframe_height();
	                    }
	                }

	            }
	        });
	    }
	function addFlowStart(_id){
		if(!_id){
			$.ligerDialog.SQalert({content:"主键ID为空.", SQ_type: "error"});
			return ;
		}
		top.$.ligerDialog.confirm("是否确认发起审核", function (flag) {
			if(flag == false){
				return ;
			}
			
		var url = '<%=path%>/rebacc/salerebaccinfo/addFlowStart.do';
		var wait_dialog;
	    $.ajax({
			type: 'get',
			dataType:'json',
			data:{id:_id},
			url: url,
			beforeSend: function(){
		          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
		     },
			success:function(msg){
				 wait_dialog.close();
				 if(msg.success == 1){
					 $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
					 grid.reload();
				 }else{
					 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
				 }
			}
		});
		})
	}
	//显示流程
    function showFlow(_pInstId,_audStsCd,_businessKey){
        if(StringUtils.isEmpty(_pInstId)){
            UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
            return;
        }
        var _formUrl = "/rebacc/salerebaccinfo/toDetailPage.do?isFlow=1@@id=";
        var params = "?pInsId="+_pInstId+"&status="+_audStsCd+"&businessKey="+_businessKey+"&formUrl="+_formUrl;
        Add_navTab('tab_spl_bank_flow_'+_pInstId,'查看流程',"<%=path%>/flow/flow/toFlowShowPageFowBus.do"+params);
    }
	function modifyAccStsCd(_id,btnTyp){
		if(!_id){
			$.ligerDialog.SQalert({content:"主键ID为空.", SQ_type: "error"});
			return ;
		}
		var url = '<%=path%>/rebacc/salerebaccinfo/modifyAccStsCd.do';
		var wait_dialog;
	    $.ajax({
			type: 'get',
			dataType:'json',
			data:{id:_id,btnTyp:btnTyp},
			url: url,
			beforeSend: function(){
		          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
		     },
			success:function(msg){
				 wait_dialog.close();
				 if(msg.success == 1){
					 $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
					 grid.reload();
				 }else{
					 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
				 }
			}
		});
	}
	function change(_id){
		if(!_id){
			$.ligerDialog.SQalert({content:"主键ID为空.", SQ_type: "error"});
			return ;
		}
		$.ligerDialog.SQopen({
            width: 900,
            height:400,
            title : '修改返利账号',
            url:'<%=path%>/rebacc/salerebaccinfo/toAddPage.do?id='+_id,
            buttons: [{
	                text: "保存", type: 'ok', cls: 'l-dialog-btn-ok',
	                onclick: function (item, Dialog) {
	                    //在子页面里绑定 frameElement.dialog.onOk = function () {}
	                    if (Dialog.onOk) Dialog.onOk();
	                }
	            }, {
	                text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
	                onclick: function (item, Dialog) {
	                    //在子页面里绑定 frameElement.dialog.onCancel = function () {}
	                    if (Dialog.onCancel) Dialog.onCancel();
	                }
	            }
	        ]
        });
	}
	var callback = function () {
		grid.reload();
    };
	function add(){
        $.ligerDialog.SQopen({
            width: 900,
            height:400,
            title : '新增返利账号',
            url:'<%=path%>/rebacc/salerebaccinfo/toAddPage.do',
            buttons: [{
	                text: "保存", type: 'ok', cls: 'l-dialog-btn-ok',
	                onclick: function (item, Dialog) {
	                    //在子页面里绑定 frameElement.dialog.onOk = function () {}
	                    if (Dialog.onOk) Dialog.onOk();
	                }
	            }, {
	                text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
	                onclick: function (item, Dialog) {
	                    //在子页面里绑定 frameElement.dialog.onCancel = function () {}
	                    if (Dialog.onCancel) Dialog.onCancel();
	                }
	            }
	        ]
        });
	}
</script>
<body  class="iframeBody">
<div class="Wrapper">
<div id="pageInTab" class="pageInTab">
	<div tabid="tabA" title="返利账户" lselected="true">
	<div class="searchArea">
	    <form id="searchBar">
	    	<div class="fieldset1 clearFix">
	            <div class="fieldBox">
	                <div class="label">收款方</div>
	                <div class="field">
	                    <input name="rcptUnt" id="rcptUnt" type="text" class="ui-textbox" value="">
	                </div>
	            </div>
	            <div class="fieldBox">
	                <div class="label">收款账号</div>
	                <div class="field">
	                    <input name="accNo" id="accNo" type="text" class="ui-textbox" value="">
	                </div>
	            </div>
	            <div class="fieldBox">
	                <div class="label">开户行</div>
	                <div class="field">
	                    <input name="bkNm" id="bkNm" type="text" class="ui-textbox" value="">
	                </div>
	            </div>
	            <div class="fieldBox">
	                <div class="label">审核状态</div>
	                <div class="field">
	                    <select name="audStsCd" id="audStsCd" data-value=" ">
	                    	<option value=" " seleted>请选择</option>
	                       <c:forEach items="${searchAudStsCdList }" var="kv">
	                     		<option value="${kv.key }">${kv.value }</option>
	                       </c:forEach>
	                    </select>
	                </div>
            	</div>
            	<div class="fieldBox">
                <div class="label">账号类型</div>
                <div class="field">
                    <select name="bizTypCd" id="bizTypCd" data-value=" ">
                    	<option value=" " seleted>请选择</option>
                       <c:forEach items="${bizTypCdList }" var="kv">
                     		<option value="${kv.key }">${kv.value }</option>
                       </c:forEach>
                    </select>
                </div>
            </div> 
            
            <div class="clearFix"></div>
			<div class="btnsBox formBtns notRight">
                <span id="searchBtn" class="sq-button-round">查询</span>
                <span id="clearBtn" class="sq-button-round">清空</span>
                <span id="addBtn" class="sq-button-round" onclick="add();">新增</span>
            </div>     
            </div>
	    </form>
	    
    </div>
    <div class="sqPanel_body">
		<div id="ligergrid1" class="sq-grid"></div>
	</div>
	</div>
	
	<div tabid="tabB" title="相关项目" id="tabBId">
			<iframe frameborder="0" name="tabB" id="tabB" src=""></iframe>
	</div>
	</div>
</div>

</body>
</html>